/*
 * @Author: Lin Hongwei
 * @Date: 2022-10-17 10:31:14
 * @LastEditTime: 2022-10-24 16:06:18
 * @LastEditors: Lin Hongwei
 * @email: 1365755396@qq.com
 * @CSDN: https://blog.csdn.net/weixin_45429409
 * @Description: 路由文件实现自动化引入,和统一设置前缀
 */
const fs = require('fs');
const path = require('path')
const Router = require('koa-router');
const router = new Router();
fs.readdirSync(__dirname).forEach(item => {
  if (item == 'index.js') return;
  const [name,suffix] = item.split('.');
  const module = require(path.join(__dirname, item))
  module.prefix(`/${name}`);//设置前缀
  router.use(module.routes())
})


router.use((err,ctx,next)=>{
  console.log("兜底错误err----",err)
})


module.exports = router